package top.chenyaohua.plug;

import org.mybatis.generator.api.IntrospectedColumn;
import org.mybatis.generator.api.IntrospectedTable;
import org.mybatis.generator.api.PluginAdapter;
import org.mybatis.generator.api.dom.java.Field;
import org.mybatis.generator.api.dom.java.TopLevelClass;

import java.util.List;

public class SwaggerPlug extends PluginAdapter {
    @Override
    public boolean validate(List<String> list) {
        return true;
    }

    @Override
    public boolean modelFieldGenerated(Field field, TopLevelClass topLevelClass, IntrospectedColumn introspectedColumn, IntrospectedTable introspectedTable, ModelClassType modelClassType) {
        topLevelClass.addImportedType("io.swagger.annotations.ApiModelProperty");
        field.addAnnotation("@ApiModelProperty(value = \""+introspectedColumn.getRemarks()+"\",example = \"\",notes = \""+introspectedColumn.getDefaultValue()+"\")");
        return true;
    }

    @Override
    public boolean modelBaseRecordClassGenerated(TopLevelClass topLevelClass, IntrospectedTable introspectedTable) {
        //添加domain的import
        topLevelClass.addImportedType("io.swagger.annotations.ApiModel");
        //添加domain的注解
        topLevelClass.addAnnotation("@ApiModel(value=\""+introspectedTable.getRemarks()+"\"");
        return true;
    }



}
